import {Component, OnInit, ViewEncapsulation} from '@angular/core';
import {Params} from '@angular/router';
import {Router} from '@angular/router';
import {ActivatedRoute} from '@angular/router';
import {GoodsTicketService} from "@goods/goods-ticket/goods-ticket.service";
import {LogisticsInfoRespVO} from "../../../../interface/goods/goods.model";


@Component({
  selector: 'seed-goods-check-logistics',
  templateUrl: './goods-check-logistics.component.html',
  styleUrls: ['./goods-check-logistics.component.scss'],
  encapsulation: ViewEncapsulation.None

})
export class GoodsCheckLogisticsComponent implements OnInit {
  public store = {
    hasData: true
  };
public orderNumber: string;
public logisticsInfo: Array<LogisticsInfoRespVO>;
public statusText: any;
  constructor(
    public route: ActivatedRoute,
    public router: Router,
    private goodsTicketService: GoodsTicketService) {
    this.route.queryParams.subscribe((params: Params) => {
      this.orderNumber = params['orderNumber'];
      this.getTicketLogistics();
    });
  }

  /**
   * @description 获取取票人信息
   * @author ouyqx-691
   * @param orderNumber 订单编号
   */
  getTicketLogistics() {
    const orderNumber = this.orderNumber;
    this.goodsTicketService.getTicketerLogistics(orderNumber).subscribe(res => {
      if (res.result === '0' && res.data) {
        this.logisticsInfo = res.data;
        this.statusChange();
        if (this.logisticsInfo.length === 0) {
          this.store.hasData = false;
        }
      }

    });
  }
  statusChange() {
    if (this.logisticsInfo[0].status === '0') { // 0：在途,1：揽件，2：疑难，3： 签收 ，4：退签 ，5：派件 ，6：退回
      this.statusText = '在途';
    }else if (this.logisticsInfo[0].status === '1') {
      this.statusText = '揽件';
    }else if (this.logisticsInfo[0].status === '2') {
      this.statusText = '疑难';
    }else if (this.logisticsInfo[0].status === '3') {
      this.statusText = '签收';
    }else if (this.logisticsInfo[0].status === '4') {
      this.statusText = '退签';
    }else if (this.logisticsInfo[0].status === '5') {
      this.statusText = '派件';
    }else if (this.logisticsInfo[0].status === '6') {
      this.statusText = '退回';
    }



  }

  ngOnInit() {
  }

}
